//
//  NetworkHelper.swift
//  XHWalletUtils
//
//  Created by xinph on 2020/5/20.
//  Copyright © 2020 xinph. All rights reserved.
//

import SPNetwork

// MARK: - SPNetwork
class NetworkHelper: SPNetwork {
    private static let _configuration = NetworkHelperConfiguration()
    static var configuration: SPNetworkConfiguration {
        return _configuration
    }
}


// MARK: - SPNetworkConfiguration
struct NetworkHelperConfiguration: SPNetworkConfiguration {
    func responseSuccessAndNeedRefresh(_ jsonObject: [String : Any]?) {
        
    }
    
    func responseSuccessAndNeedReLogin(_ jsonObject: [String : Any]?) {
        
    }
    
    func responseSuccessAndCurrentTime(_ jsonObject: [String : Any]?) {
        
    }
    
    
    func networkBreakdown(error: SPError) {
        print("网络错误!code=\(error._code)")
    }
    
    func serverBreakdown(code: Int) {
        print("服务器错误!code=\(code)")
    }
    
    func responseSuccessFilter(_ jsonObject: [String : Any]?) {
        print("过滤并处理特殊的返回值")
    }
    
    var commonParameters: [String : Any] {
        var targetParam = [String: Any]()
        return targetParam
    }
    
    var enableNetworkLogger: Bool {
        return true
    }
}

enum NetworkHelperService: SPTargetType {
    
    case sendTransation

    
    /// 服务器地址
    var baseURL: URL {
        #if DEBUG
        return URL(string: "")!
        #else
        return URL(string: "")!
        #endif
    }
    
    /// 请求地址
    var path: String {
        let path: String
        switch self {
        case .sendTransation:
            path = ""
        }
        return path
    }
    
    /// 类型
    var method: SPMethod {
        return .post
    }
    
    var sampleData: Data{return "".data(using: .utf8)!}
    
    /// 开启请求
    var task: SPTask {
        switch self {
        case .sendTransation:
            return .requestParameters(parameters: [:], encoding: SPDefaultJSONEncoding)
        }
    }
}
